package Java实训.第四天异常;

public class Num1 {
    public static void main(String[] args) {

        try {
            System.out.println(5/0);
        } catch (ArithmeticException e) {
            System.out.println("这是一个算数异常");
        }
        try {
            int[] arr1 = null;
            System.out.println(arr1[1]);
        }catch (NullPointerException e){
            System.out.println("这是一个空指针异常");
        }
        try {
            int[] arr2 = {1,2,3,4,5};
            System.out.println(arr2[arr2.length]);
        } catch (ArrayIndexOutOfBoundsException e){
            System.out.println("这是一个数组下标越界异常");
        }
        try {
            String str = "abc";
            int a = Integer.parseInt(str);
        } catch (NumberFormatException e) {
            System.out.println("这是一个字符串转化为数字异常");
        }
        try {
            Object x = new Integer(3);
            System.out.println((String)x);
        } catch (ClassCastException e) {
            System.out.println("这是一个强制类型转换异常");
        }
        System.out.println("程序运行结束");
    }
}
